# coding:utf-8
# 承接outcome里的数据进行进一步过滤

import pandas as pd
import numpy as np
from sklearn.feature_selection import VarianceThreshold
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2


data = pd.read_csv(r'C:\Users\LDK‘s PC\Desktop\大三上工程研究与实习\机器学习\data\arff\outcome\EQ.csv')
data.head()
data.shape

# 方差过滤
# 缺失值处理
data.fillna(0,inplace = True)
# 切分特征与标签
x,y = data.iloc[:,:-1],data.iloc[:,-1]
# 以方差中位数作为阈值进行方差过滤
medium_var = np.median(x.var())
model_var = VarianceThreshold(threshold=medium_var)
x_var_medium = model_var.fit_transform(x)
x_var_medium.shape

# 卡方过滤
model_chi2 = SelectKBest(chi2,k=29)
x_chi2 = model_chi2.fit_transform(x_var_medium,y)
x_chi2.shape


data.to_csv(f'data/arff/feature/EQ.csv', index=False)

